package com.laowang.project.system.service.impl;

import java.math.BigDecimal;
import java.util.List;

import com.laowang.common.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.laowang.project.system.mapper.ZcActivityMapper;
import com.laowang.project.system.domain.ZcActivity;
import com.laowang.project.system.service.ZcActivityService;

/**
 * 众筹活动Service业务层处理
 *
 * @author laowang
 * @date 2025-09-09
 */
@Service
public class ZcActivityServiceImpl implements ZcActivityService {
    @Autowired
    private ZcActivityMapper zcActivityMapper;

    /**
     * 查询众筹活动
     *
     * @param id 众筹活动ID
     * @return 众筹活动
     */
    @Override
    public ZcActivity selectZcActivityById(Integer id) {
        return zcActivityMapper.selectZcActivityById(id);
    }

    /**
     * 查询众筹活动列表
     *
     * @param zcActivity 众筹活动
     * @return 众筹活动
     */
    @Override
    public List<ZcActivity> selectZcActivityList(ZcActivity zcActivity) {
        return zcActivityMapper.selectZcActivityList(zcActivity);
    }

    /**
     * 新增众筹活动
     *
     * @param zcActivity 众筹活动
     * @return 结果
     */
    @Override
    public int insertZcActivity(ZcActivity zcActivity) {
        zcActivity.setCreateTime(DateUtils.getNowDate());
        return zcActivityMapper.insertZcActivity(zcActivity);
    }

    /**
     * 修改众筹活动
     *
     * @param zcActivity 众筹活动
     * @return 结果
     */
    @Override
    public int updateZcActivity(ZcActivity zcActivity) {
        return zcActivityMapper.updateZcActivity(zcActivity);
    }

    /**
     * 批量删除众筹活动
     *
     * @param ids 需要删除的众筹活动ID
     * @return 结果
     */
    @Override
    public int deleteZcActivityByIds(Integer[] ids) {
        return zcActivityMapper.deleteZcActivityByIds(ids);
    }

    /**
     * 删除众筹活动信息
     *
     * @param id 众筹活动ID
     * @return 结果
     */
    @Override
    public int deleteZcActivityById(Integer id) {
        return zcActivityMapper.deleteZcActivityById(id);
    }

    @Override
    public ZcActivity selectZcActivityDetailById(Integer id) {
        return zcActivityMapper.selectZcActivityDetailById(id);
    }

    @Override
    public Integer selectCountOrder(Integer activityId) {
        return zcActivityMapper.selectCountOrder(activityId);
    }

    @Override
    public synchronized void updateAmount(Integer activityId, BigDecimal totalPrice) {
        ZcActivity zcActivity = selectZcActivityById(activityId);
        BigDecimal haveAmount = zcActivity.getHaveAmount();
        haveAmount = haveAmount.add(totalPrice);
        zcActivity.setHaveAmount(haveAmount);
        zcActivityMapper.updateZcActivity(zcActivity);
    }
}
